﻿using System.IO;
using UnityEditor;
using UnityEngine;
using Util;
namespace UtilEditors
{
    public enum SaveKey
    {
        AliasSettingWindow,
    }
    public class EditorSave
    {
        #region 自己封装
        private const string Name = "EditorConfig.Config";
        private const string Com = "Com";
        private static EditorSave save;

        public static EditorSave Save
        {
            get
            {
                if (save.isNull())
                {
                    save = new EditorSave();
                    save.init();
                }
                return save;
            }
        }
        ConfigFileSave config;
        public void init()
        {
            var path = Application.dataPath + "/Editor/";
            config = ConfigFileSave.Load(path, Name);
        }
        static public T GetObj<T>(SaveKey key)
        {
            return GetObj<T>(key.ToString());
        }

        static public void SaveObj<T>(SaveKey key, T v)
        {
            SaveObj(key.ToString(), v);
        }
        static public T GetObj<T>(string key)
        {
            var vs = Save.config.Get(Com, key);
            var t = SerializeJosn.Desrialize<T>(vs);
            return t;
        }

        static public void SaveObj<T>(string key, T v)
        {
            var vs = SerializeJosn.Serialize(v);
            Save.config.Set(Com, key, vs);
            Save.config.Save();
        }
        #endregion

        #region 系统的编辑器存储
        public static void SetConfigValue<T>(string k, T v)
        {
            SetConfigValue(k, SerializeJosn.Serialize(v));
        }
        public static T GetConfigValue<T>(string k)
        {
            return SerializeJosn.Desrialize<T>(GetConfigValue(k));
        }

        public static void SetConfigValue(string k, string v)
        {
            EditorUserSettings.SetConfigValue(k, v);
        }
        public static string GetConfigValue(string k)
        {
            return EditorUserSettings.GetConfigValue(k);
        }
        //EditorUserSettings.SetConfigValue( key.ToString(), vs);
        //return EditorUserSettings.GetConfigValue(key.ToString()).toInt();
        //Library/EditorUserSettings.asset
        #endregion

    }
}